/**
 * Copyright (c) 2016 Lenovo Group
 * All Rights Reserved.
 * 
 * Project Name:app-gateway
 * Create Time: 2016年1月19日 上午9:58:11
 */
package com.lenovo.lmrp.server.appgateway.mock;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import javax.ws.rs.Consumes;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import com.lenovo.lmrp.api.appgateway.IAppSoftware;
import com.lenovo.lmrp.api.model.RestResponse;
import com.lenovo.lmrp.api.model.view.AppVO;
import com.lenovo.lmrp.api.model.view.FeedbackVO;
import com.lenovo.lmrp.api.model.view.LoginData;
import com.lenovo.lmrp.api.model.view.TokenVO;
import com.lenovo.lmrp.server.appgateway.util.TokenGenerator;
import com.lenovo.sdc.framework.annotation.RestService;

/**
 * @author zhangzhenga
 *
 */
@RestService
@Path("/app/v1")
@Consumes("application/json;charset-utf-8")
@Produces("application/json;charset-utf-8")
public class MockAppSoftwareImpl implements IAppSoftware {

    /* (non-Javadoc)
     * @see com.lenovo.lmrp.api.appgateway.IAppSoftware#login(java.lang.String, com.lenovo.lmrp.api.model.view.LoginData)
     */
    public RestResponse<TokenVO> login(String itsmcode, LoginData loginData) {

        String loginname = loginData.getLoginname();
        if (loginname.endsWith("1")) {
            return new RestResponse<TokenVO>(1, "帐号不存在", null);
        }
        if (loginname.endsWith("2")) {
            return new RestResponse<TokenVO>(1, "帐号或密码错误", null);
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
        TokenGenerator generator = new TokenGenerator();
        TokenVO tokenVO = new TokenVO();
        tokenVO.setToken(generator.accessToken());
        tokenVO.setRefreshtoken(generator.refreshToken());
        tokenVO.setExpiretime(new Date());
        return new RestResponse<TokenVO>(0, "OK", tokenVO);
    }

    /* (non-Javadoc)
     * @see com.lenovo.lmrp.api.appgateway.IAppSoftware#logout(java.lang.String)
     */
    public RestResponse<Integer> logout(String itsmcode) {
        return new RestResponse<Integer>(0, "OK", 1);
    }

    /* (non-Javadoc)
     * @see com.lenovo.lmrp.api.appgateway.IAppSoftware#getLastVersion(java.lang.String)
     */
    public RestResponse<AppVO> getLastVersion(String appName) {
        // TODO Auto-generated method stub
        return null;
    }

    /* (non-Javadoc)
     * @see com.lenovo.lmrp.api.appgateway.IAppSoftware#feedback(java.lang.String, com.lenovo.lmrp.api.model.view.FeedbackVO)
     */
    public RestResponse<AppVO> feedback(String appName, FeedbackVO feedback) {
        // TODO Auto-generated method stub
        return null;
    }

    /* (non-Javadoc)
     * @see com.lenovo.lmrp.api.appgateway.IAppSoftware#refresh(java.lang.String, java.lang.String)
     */
    public RestResponse<TokenVO> refresh(String itsmcode, Map<String, String> refreshToken) {

        TokenGenerator generator = new TokenGenerator();
        TokenVO tokenVO = new TokenVO();
        tokenVO.setToken(generator.accessToken());
        tokenVO.setRefreshtoken(generator.refreshToken());
        tokenVO.setExpiretime(new Date());
        return new RestResponse<TokenVO>(0, "OK", tokenVO);
    }

}
